﻿function ScopeContainer(position, size, color, parmas) {
    NodeContainer.apply(this, [position, size, color, parmas]);

    this._isCollapse = parmas.expand;
    this._expand = svg.append('image').attr("xlink:href", imageMap["collapse"]).attr("width", 16).attr("height", 16);
    this._group = svg.append('image').attr("xlink:href", imageMap["group"]).attr("width", 16).attr("height", 16);
    this._unpin = svg.append('image').attr("xlink:href", imageMap["unpin"]).attr("width", 16).attr("height", 16);
    this._menu = svg.append('image').attr("xlink:href", imageMap["menu"]).attr("width", 16).attr("height", 16);

    this.onUpdateLayout = function () {
        var posy = this.getActualPosition().y - 7;
        var rx = parmas.r;
        if (this._isCollapse == "true") {
            this.collapse();
            posy = posy + 10;
            rx = 7.5;
        }
        this._domEl.attr("x", this.getActualPosition().x)
            .attr("y", this.getActualPosition().y)
            .attr("width", this.getSize().w)
            .attr("id", parmas.id)
            .attr("height", this.getSize().h)
            .attr("rx", rx).attr("ry", rx);

        this._expand.attr("x", this.getActualPosition().x + this.getSize().w * 0.8).attr("y", posy);
        this._group.attr("x", this.getActualPosition().x + this.getSize().w * 0.1).attr("y", posy);
        this._unpin.attr("x", this.getActualPosition().x + this.getSize().w * 0.8 - 20).attr("y", this.getActualPosition().y - 8);
        this._menu.attr("x", this.getActualPosition().x + this.getSize().w * 0.8 + 20).attr("y", this.getActualPosition().y - 8);

        for (var i = 0; i < this.children.length; i++) {
            this.children[i].updateLayout();
        }
        if (this.logFlag) {
            worker.postMessage("Create a Image:  x:" + this._position.x + ", y:" + this._position.x + ", width:" + this._size.w + ", height:" + this._size.h);
        }
        this.logFlag = false;
    };

    this.hide = function () {
        this._unpin.attr("display", "none");
        this._menu.attr("display", "none");
        this._expand.attr("display", "none");
        this._group.attr("display", "none");

        this._domEl.attr("display", "none");
        for (var i = 0; i < this.addChildren.length; i++) {
            this.addChildren[i].hide();
        }
    }

    this.collapse = function () {
        for (var i = 0; i < this.children.length; i++) {
            this.children[i].hide();
        }
        this._unpin.attr("display", "none");
        this._menu.attr("display", "none");
        this._isCollapse = "true";
        this._expand.attr("xlink:href", imageMap["uncollapse"]);
    }

}